<?php

declare (strict_types = 1);

namespace app\common\service\system;

use app\common\service\BaseService;
use app\common\repository\system\AdminLoginLogRepository;


class AdminLoginLogService extends BaseService
{
    public function __construct(AdminLoginLogRepository $repository)
    {
        $this->repository = $repository;
    }

    /**
     * 登录日志列表
     *
     * @param array $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     */
    public function getList(array $where = []): array
    {
        [$page, $pageSize] = $this->getPaginationParams();
        unset($where['page'], $where['page_size']);
        return $this->repository->paginate($where, ['id' => 'desc'], $page, $pageSize);
    }

    /**
     * 获取一条日志
     *
     * @param $id
     * @return \app\common\model\BaseModel|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getInfo($id): ?\app\common\model\BaseModel
    {
        return $this->repository->getOne($id);
    }

    /**
     * 新增日志信息
     *
     * @param array $data
     * @return \app\common\model\BaseModel|array|\think\Collection
     * @throws \Exception
     */
    public function create(array $data): \think\Collection|\app\common\model\BaseModel|array
    {
        return $this->repository->save($data);
    }
}